﻿using System;
using System.Data;
using BLL;
using DAL;
using Ext.Net;
using Roles;

namespace ERP.Modules
{
    public partial class OrderBuySell : System.Web.UI.UserControl
    {
        #region[Define]
        private static bool _flag;
        private readonly BllOrder_Sell _clsOrderSell = new BllOrder_Sell();
        private readonly Customer_BLL _clsCustomer = new Customer_BLL();
        #endregion

        #region[Controler]
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                CheckPermisstion();
                txtDateBegin.Text = DateTime.Now.ToString();
                GetOrderSell();
                btnEdit.Disable(true);
                btnDel.Disable(true);
                btnReview.Disable(true);
            }
        }
        //Store
        protected void StoreSell_RefreshData(object sender, StoreReadDataEventArgs e)
        {
            txtSearch.Text = string.Empty;
            SelectBoxReview.Text = string.Empty;
            txtDateBeginFillter.Text = string.Empty;
            txtDateEndFillter.Text = string.Empty;
            GetOrderSell();
        }
        protected void StoreOrderSell_Detail_RefreshData(object sender, StoreReadDataEventArgs e)
        {
            if (_flag)
            {
                GetOrderDetailTemp();
                GetOrderSellSum();
            }
            else
            {
                GetOrderDetailGridEdit(int.Parse(txtOrderSell_ID.Text));
                GetOrderSellSumEdit(int.Parse(txtOrderSell_ID.Text));
            }
        }
        protected void StoreOrderSell_Proposed_Materials_RefreshData(object sender, StoreReadDataEventArgs e)
        {
            GetOrderMaterialSell();
        }
        protected void StoreOrderCustomerSell_Proposed_Materials_RefreshData(object sender, StoreReadDataEventArgs e)
        {
            GetCustomer();
        }
        //Button
        protected void btnAddNew_Click(object sender, DirectEventArgs e)
        {
            try
            {
                _flag = true;
                GetAutoID();
                ClearText();
                txtOrderSellCode.ReadOnly = false;
                btnRefreshSellCode.Enable(true);
                btnSavePopUp.Enable(true);
                btnAddMaterial.Enable(true);
                btnDelMaterial.Enable(true);
                btnAddCustomer.Enable(true);
                var obj = new EtOrderSellDetail {Users_Id = int.Parse(Session["Users_Id"].ToString())};
                BllOrder_Sell.DeleteSellOrderDetail(obj);
                GetOrderDetailTemp();
                WindowsOrderSell.Show();
            }
            catch (Exception ex)
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", ex.Message);
            }
            
        }
        protected void btnEdit_Click(object sender, DirectEventArgs e)
        {
            var sm = grSell.GetSelectionModel() as CheckboxSelectionModel;
            if (sm != null)
                foreach (var row in sm.SelectedRows)
                {
                    _flag = false;
                    txtOrderSellCode.ReadOnly = true;
                    btnRefreshSellCode.Disable(true);
                    GetOrderSellEdit(int.Parse(row.RecordID));
                    GetOrderDetailGridEdit(int.Parse(row.RecordID));
                    GetOrderSellSumEdit(int.Parse(row.RecordID));
                    WindowsOrderSell.Show();
                }
        }
        protected void btnDel_Click(object sender, DirectEventArgs e)
        {
            var sm = grSell.GetSelectionModel() as CheckboxSelectionModel;
            if (sm != null)
                foreach (var row in sm.SelectedRows)
                {
                    try
                    {
                        var obj = new EtOrderSell { Order_Sell_Id = int.Parse(row.RecordID) };
                        BllOrder_Sell.DeleteSellOrder(obj);
                        if (obj.Msg == 0)
                        {
                            HTML.clsFormat.Alert_ERROR("Lỗi",
                                "Phiếu đề nghị đặt hàng này đã được xét duyệt.Không thể xoá !");
                        }
                        else if (obj.Msg == 2)
                        {
                            HTML.clsFormat.Alert_ERROR("Lỗi",
                                "Tồn tại tài liệu con, không xoá được vui lòng xoá tài liệu con trước  !");
                        }
                    }
                    catch (Exception)
                    {
                        HTML.clsFormat.Alert_ERROR("Thông Báo", "Tồn tại tài liệu con, không xoá được vui lòng xoá tài liệu con trước !");
                    }
                }
            GetOrderSell();
        }
        protected void btnFillter_Click(object sender, DirectEventArgs e)
        {
            GetOrderFillterDate();
        }
        protected void btnSavePopUp_Click(object sender, DirectEventArgs e)
        {
            if (_flag)
            {
                InsertOrderSell();
            }
            else
            {
                UpdateOrder();
            }
        }
        protected void btnCancelPopUp_Click(object sender, DirectEventArgs e)
        {
            WindowsOrderSell.Close();
        }
        protected void btnAddOrderSellMaterials_Click(object sender, DirectEventArgs e)
        {
            GetOrderDetailTemp();
        }
        protected void btnSelectOrderSell_Proposed_Materials_Click(object sender, DirectEventArgs e)
        {
            if (_flag)
            {
                InsertOrderSellDetail();
            }
            else
            {
                InsertOrderSellDetailEdit();
            }
        }
        protected void btnAddMaterial_Click(object sender, DirectEventArgs e)
        {
            var sm = grOrderSell_Proposed_Materials.GetSelectionModel() as CheckboxSelectionModel;
            if (sm != null) sm.DeselectAll();
            GetOrderMaterialSell();
            WindowOrderSell_Proposed_Materials.Show();
        }
        protected void btnAddCustomer_Click(object sender, DirectEventArgs e)
        {
            var sm = grCustomerSell.GetSelectionModel() as CheckboxSelectionModel;
            if (sm != null) sm.DeselectAll();
            GetCustomer();
            WindowCustomerSell.Show();
        }
        protected void btnRefreshSellCode_Click(object sender, DirectEventArgs e)
        {
            GetAutoID();
        }
        protected void btnDelMaterial_Click(object sender, DirectEventArgs e)
        {
            if (_flag)
            {
                var sm = grOrderSell_Detail.GetSelectionModel() as CheckboxSelectionModel;
                if (sm != null)
                    foreach (var row in sm.SelectedRows)
                    {
                        try
                        {
                            var obj = new EtOrderSellDetail { Order_Sell_Detail_Id = int.Parse(row.RecordID) };
                            BllOrder_Sell.DeleteSellDetailMaterial(obj);
                        }
                        catch (Exception)
                        {
                            HTML.clsFormat.Alert_ERROR("Thông Báo", "Tồn tại tài liệu con, không xoá được vui lòng xoá tài liệu con trước !");
                        }
                    }
                GetOrderDetailTemp();
                GetOrderSellSum();
            }
            else
            {
                var sm = grOrderSell_Detail.GetSelectionModel() as CheckboxSelectionModel;
                if (sm != null)
                    foreach (var row in sm.SelectedRows)
                    {
                        try
                        {
                            var obj = new EtOrderSellDetail { Order_Sell_Detail_Id = int.Parse(row.RecordID) };
                            BllOrder_Sell.DeleteSellDetailMaterial(obj);
                        }
                        catch (Exception)
                        {
                            HTML.clsFormat.Alert_ERROR("Thông Báo", "Tồn tại tài liệu con, không xoá được vui lòng xoá tài liệu con trước !");
                        }
                    }
                GetOrderDetailGridEdit(int.Parse(txtOrderSell_ID.Text));
                GetOrderSellSumEdit(int.Parse(txtOrderSell_ID.Text));
            }
        }
        protected void btnReview_Click(object sender, DirectEventArgs e)
        {
            var sm = grSell.GetSelectionModel() as CheckboxSelectionModel;
            var smsub = grOrderSellReview.GetSelectionModel() as CheckboxSelectionModel;
            if (sm != null)
                foreach (var row in sm.SelectedRows)
                {
                    GetOrderSellReview(int.Parse(row.RecordID));
                    GetOrderDetailGridReview(int.Parse(row.RecordID));
                    GetOrderSellSumEdit(int.Parse(row.RecordID));
                    WindowOrderSellReview.Show();
                }

            if (smsub != null)
            {
                smsub.DeselectAll();
            }
        }
        //Search
        protected void Search_Event(object sender, DirectEventArgs e)
        {
            var dtSearch = _clsOrderSell.GetOrderSell(txtSearch.Text);
            if (dtSearch != null && dtSearch.Rows.Count > 0)
            {
                StoreSell.DataSource = dtSearch;
                StoreSell.DataBind();
            }
            else
            {
                grSell.GetStore().RemoveAll();
            }
        }
        //Double-Click
        protected void SellDblClick(object sender, DirectEventArgs e)
        {
            _flag = false;
            txtOrderSellCode.ReadOnly = true;
            btnRefreshSellCode.Disable(true);
            int Order_Sell_Id = int.Parse(e.ExtraParams["Order_Sell_Id"]);
            GetOrderSellEdit(Order_Sell_Id);
            GetOrderDetailGridEdit(Order_Sell_Id);
            GetOrderSellSumEdit(Order_Sell_Id);
            WindowsOrderSell.Show();
        }
        //Cell-Click
        protected void UpdateMaterials_Click(object sender, DirectEventArgs e)
        {
            var GetSellOrder_Detail = e.ExtraParams["grOrderSell_Detail"];
            var dtSellOrder_Detail = JSON.Deserialize<DataTable>(GetSellOrder_Detail);
            if (_flag)
            {
                #region[Bán lẽ]

                if (dtSellOrder_Detail.Rows.Count == 0)
                {
                    HTML.clsFormat.Alert_ERROR("Thông Báo", "Vui lòng thêm sản phẩm đề nghị mua hàng !");
                }
                else
                {
                    foreach (DataRow rows in dtSellOrder_Detail.Rows)
                    {
                        var obj = new EtOrderSellDetail
                        {
                            Materials_Id = int.Parse(rows["Materials_Id"].ToString()),
                            Order_Sell_Detail_Id = int.Parse(rows["Order_Sell_Detail_Id"].ToString()),
                            Order_Detail_Quality = int.Parse(rows["Order_Detail_Quality"].ToString()),
                            Order_Detail_Price = float.Parse(rows["Order_Detail_Price"].ToString()),
                            Order_Detail_CK_Percent = float.Parse(rows["Order_Detail_CK_Percent"].ToString()),
                            Order_Detail_VAT_Percent = float.Parse(rows["Order_Detail_VAT_Percent"].ToString()),
                            Order_Detail_Quality_Remain = 0,
                            Users_Id = int.Parse(Session["Users_Id"].ToString()),
                            Flag = 1
                        };
                        BllOrder_Sell.UpdateQuanlityOrder(obj);
                        if (obj.Msg == 0)
                            HTML.clsFormat.Alert_ERROR("Lỗi", "Số lượng mua hàng phải nhỏ hơn số lượng trong kho !");
                        else
                            HTML.clsFormat.Alert_INFO("Thông Báo", "Cập nhật thành công !");
                    }
                    GetOrderDetailTemp();
                    GetOrderSellSum();
                }
                #endregion

                #region[Giá Gốc]
                //if (dtSellOrder_Detail.Rows.Count == 0)
                //{
                //    HTML.clsFormat.Alert_ERROR("Thông Báo", "Vui lòng thêm sản phẩm đề nghị mua hàng !");
                //}
                //else
                //{
                //    foreach (DataRow rows in dtSellOrder_Detail.Rows)
                //    {
                //        var obj = new EtOrderSellDetail
                //        {
                //            Materials_Id = int.Parse(rows["Materials_Id"].ToString()),
                //            Order_Sell_Detail_Id = int.Parse(rows["Order_Sell_Detail_Id"].ToString()),
                //            Order_Detail_Quality = int.Parse(rows["Order_Detail_Quality"].ToString()),
                //            Order_Detail_CK_Percent = float.Parse(rows["Order_Detail_CK_Percent"].ToString()),
                //            Order_Detail_VAT_Percent = float.Parse(rows["Order_Detail_VAT_Percent"].ToString()),
                //            Order_Detail_Quality_Remain = 0,
                //            Users_Id = int.Parse(Session["Users_Id"].ToString()),
                //            Flag = 1
                //        };
                //        BllOrder_Sell.UpdateQuanlityOrderRoot(obj);
                //        if (obj.Msg == 0)
                //            HTML.clsFormat.Alert_ERROR("Lỗi", "Số lượng mua hàng phải nhỏ hơn số lượng trong kho !");
                //        else
                //            HTML.clsFormat.Alert_INFO("Thông Báo", "Cập nhật thành công !");
                //    }
                //    GetOrderDetailTemp();
                //    GetOrderSellSum();
                //}
                #endregion
            }
            else
            {
                if (txtIsActive.Text == "True")
                {
                    HTML.clsFormat.Alert_ERROR("Lỗi", "Phiếu đề nghị đã được phê duyệt,không thể thay đổi !");
                }
                else
                {
                    if (CheckPermisstionDobclick())
                    {
                        HTML.clsFormat.Alert_ERROR("Thông Báo", "Bạn không được cấp quyền sửa đổi");
                    }
                    else
                    {
                        #region[Bán lẽ]

                        if (dtSellOrder_Detail.Rows.Count == 0)
                        {
                            HTML.clsFormat.Alert_ERROR("Thông Báo", "Vui lòng thêm sản phẩm đề nghị mua hàng !");
                        }
                        else
                        {
                            foreach (DataRow rows in dtSellOrder_Detail.Rows)
                            {
                                var obj = new EtOrderSellDetail
                                {
                                    Materials_Id = int.Parse(rows["Materials_Id"].ToString()),
                                    Order_Sell_Detail_Id = int.Parse(rows["Order_Sell_Detail_Id"].ToString()),
                                    Order_Detail_Quality = int.Parse(rows["Order_Detail_Quality"].ToString()),
                                    Order_Detail_Price = float.Parse(rows["Order_Detail_Price"].ToString()),
                                    Order_Detail_CK_Percent = float.Parse(rows["Order_Detail_CK_Percent"].ToString()),
                                    Order_Detail_VAT_Percent = float.Parse(rows["Order_Detail_VAT_Percent"].ToString()),
                                    Order_Detail_Quality_Remain = 0,
                                    Users_Id = int.Parse(Session["Users_Id"].ToString()),
                                    Flag = 0
                                };
                                BllOrder_Sell.UpdateQuanlityOrder(obj);
                                if (obj.Msg == 0)
                                    HTML.clsFormat.Alert_ERROR("Lỗi", "Số lượng mua hàng phải nhỏ hơn số lượng trong kho !");
                                else
                                    HTML.clsFormat.Alert_INFO("Thông Báo", "Cập nhật thành công !");
                            }
                            GetOrderDetailGridEdit(int.Parse(txtOrderSell_ID.Text));
                            GetOrderSellSumEdit(int.Parse(txtOrderSell_ID.Text));
                        }
                        #endregion

                        #region[Giá Gốc]
                        //if (dtSellOrder_Detail.Rows.Count == 0)
                        //{
                        //    HTML.clsFormat.Alert_ERROR("Thông Báo", "Vui lòng thêm sản phẩm đề nghị mua hàng !");
                        //}
                        //else
                        //{
                        //    foreach (DataRow rows in dtSellOrder_Detail.Rows)
                        //    {
                        //        var obj = new EtOrderSellDetail
                        //        {
                        //            Materials_Id = int.Parse(rows["Materials_Id"].ToString()),
                        //            Order_Sell_Detail_Id = int.Parse(rows["Order_Sell_Detail_Id"].ToString()),
                        //            Order_Detail_Quality = int.Parse(rows["Order_Detail_Quality"].ToString()),
                        //            Order_Detail_CK_Percent = float.Parse(rows["Order_Detail_CK_Percent"].ToString()),
                        //            Order_Detail_VAT_Percent = float.Parse(rows["Order_Detail_VAT_Percent"].ToString()),
                        //            Order_Detail_Quality_Remain = 0,
                        //            Users_Id = int.Parse(Session["Users_Id"].ToString()),
                        //            Flag = 0
                        //        };
                        //        BllOrder_Sell.UpdateQuanlityOrderRoot(obj);
                        //        if (obj.Msg == 0)
                        //            HTML.clsFormat.Alert_ERROR("Lỗi", "Số lượng mua hàng phải nhỏ hơn số lượng trong kho !");
                        //        else
                        //            HTML.clsFormat.Alert_INFO("Thông Báo", "Cập nhật thành công !");
                        //    }
                        //    GetOrderDetailGridEdit(int.Parse(txtOrderSell_ID.Text));
                        //    GetOrderSellSumEdit(int.Parse(txtOrderSell_ID.Text));
                        //}
                        #endregion
                    }
                }
            }
        }
        protected void UpdateReview_Click(object sender, DirectEventArgs e)
        {
            var GetSellOrder_Detail = e.ExtraParams["grOrderSellReview"];
            var dtSellOrder_Detail = JSON.Deserialize<DataTable>(GetSellOrder_Detail);
            if (txtIsActive.Text == "True")
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", "Phiếu đề nghị đã được phê duyệt,không thể thay đổi !");
            }
            else
            {
                if (CheckPermisstionDobclick())
                {
                    HTML.clsFormat.Alert_ERROR("Thông Báo", "Bạn không được cấp quyền sửa đổi");
                }
                else
                {
                    #region[Bán lẽ]

                    if (dtSellOrder_Detail.Rows.Count == 0)
                    {
                        HTML.clsFormat.Alert_ERROR("Thông Báo", "Vui lòng thêm sản phẩm đề nghị mua hàng !");
                    }
                    else
                    {
                        foreach (DataRow rows in dtSellOrder_Detail.Rows)
                        {
                            var obj = new EtOrderSellDetail
                            {
                                Materials_Id = int.Parse(rows["Materials_Id"].ToString()),
                                Order_Sell_Detail_Id = int.Parse(rows["Order_Sell_Detail_Id"].ToString()),
                                Order_Detail_Quality = int.Parse(rows["Order_Detail_Quality"].ToString()),
                                Order_Detail_Price = float.Parse(rows["Order_Detail_Price"].ToString()),
                                Order_Detail_CK_Percent = float.Parse(rows["Order_Detail_CK_Percent"].ToString()),
                                Order_Detail_VAT_Percent = float.Parse(rows["Order_Detail_VAT_Percent"].ToString()),
                                Order_Detail_Quality_Remain = 0,
                                Users_Id = int.Parse(Session["Users_Id"].ToString()),
                                Flag = 0
                            };
                            BllOrder_Sell.UpdateQuanlityOrder(obj);
                            if (obj.Msg == 0)
                                HTML.clsFormat.Alert_ERROR("Lỗi", "Số lượng mua hàng phải nhỏ hơn số lượng trong kho !");
                            else
                                HTML.clsFormat.Alert_INFO("Thông Báo", "Cập nhật thành công !");
                        }
                        GetOrderSellReview(int.Parse(txtReviewOrder_Sell_Id.Text));
                        GetOrderDetailGridReview(int.Parse(txtReviewOrder_Sell_Id.Text));
                        GetOrderSellSumEdit(int.Parse(txtReviewOrder_Sell_Id.Text));
                    }
                    #endregion
                }
            }
        }
        protected void CellOrderSellCustomer_Click(object sender, DirectEventArgs e)
        {
            var sm = grCustomerSell.GetSelectionModel() as CellSelectionModel;
            if (sm != null)
            {
                string id = sm.SelectedCell.RecordID;
                GetCustomerEdit(int.Parse(id));
            }
            if (sm != null)
            {
                sm.Clear();
                sm.UpdateSelection();
            }
            WindowCustomerSell.Close();
        }
        //Select-Box
        protected void SelectBoxSellWarrehouse_Change(object sender, DirectEventArgs e)
        {
            
        }
        protected void SelectBoxSellRoom_Change(object sender, DirectEventArgs e)
        {

        }
        protected void SelectType_Change(object sender, DirectEventArgs e)
        {
            /*
             *  0       : Đơn giá bán lẽ
             *  1       : Đơn giá gốc  
             *  True    : Ẩn
             *  False   : Hiện
             */
            if (SelectType.SelectedItem.Value == "0")
            {
                grOrderSell_Detail.ColumnModel.GetColumnByDataIndex("Order_Detail_Price").Hidden = false;
                grOrderSell_Detail.ColumnModel.GetColumnByDataIndex("Price_Initially").Hidden = true;
            }
            else
            {
                grOrderSell_Detail.ColumnModel.GetColumnByDataIndex("Order_Detail_Price").Hidden = true;
                grOrderSell_Detail.ColumnModel.GetColumnByDataIndex("Price_Initially").Hidden = false;
            }
        }
        protected void SelectBoxReview_Change(object sender, DirectEventArgs e)
        {
            GetOrderSell();
        }
        #endregion

        #region[Method]
        private void GetOrderSell()
        {
            if (String.IsNullOrEmpty(SelectBoxReview.Text))
            {
                var _dtGetOrderSell = _clsOrderSell.GetOrderSell(txtSearch.Text);
                if (_dtGetOrderSell != null && _dtGetOrderSell.Rows.Count > 0)
                {
                    StoreSell.DataSource = _dtGetOrderSell;
                    StoreSell.DataBind();
                }
                else
                {
                    grSell.GetStore().RemoveAll();
                }
            }
            else
            {
                var _dtGetOrderSell = _clsOrderSell.GetOrderSellIsActive(int.Parse(SelectBoxReview.SelectedItem.Value));
                if (_dtGetOrderSell != null && _dtGetOrderSell.Rows.Count > 0)
                {
                    StoreSell.DataSource = _dtGetOrderSell;
                    StoreSell.DataBind();
                }
                else
                {
                    grSell.GetStore().RemoveAll();
                }
            }
        }
        private void GetOrderSellEdit(int id)
        {
            var _dtGetOrderSellEdit = _clsOrderSell.GetOrderSellEdit(id);
            if (_dtGetOrderSellEdit != null && _dtGetOrderSellEdit.Rows.Count > 0)
            {
                txtOrderSell_ID.Text = _dtGetOrderSellEdit.Rows[0]["Order_Sell_Id"].ToString();
                txtOrderSellCode.Text = _dtGetOrderSellEdit.Rows[0]["Order_Sell_Code"].ToString();
                txtDateBegin.Text = _dtGetOrderSellEdit.Rows[0]["Order_Sell_DateBegin"].ToString();
                txtCustomerAlias.Text = _dtGetOrderSellEdit.Rows[0]["Customer_Alias"].ToString();
                txtCustomerName.Text = _dtGetOrderSellEdit.Rows[0]["Customer_Name"].ToString();
                txtCustomerID.Text = _dtGetOrderSellEdit.Rows[0]["Customer_ID"].ToString();
                txtTaxCode.Text = _dtGetOrderSellEdit.Rows[0]["Order_Sell_Tax_Code"].ToString();
                txtCustomerAddress.Text = _dtGetOrderSellEdit.Rows[0]["Customer_Address"].ToString();
                txtNote.Text = _dtGetOrderSellEdit.Rows[0]["Note"].ToString();
                txtIsActive.Text = _dtGetOrderSellEdit.Rows[0]["IsActive"].ToString();
                txtTaxCode.Text = _dtGetOrderSellEdit.Rows[0]["Customer_Contract_Tax_Code"].ToString();
                if ((bool)_dtGetOrderSellEdit.Rows[0]["IsActive"])
                {
                    btnSavePopUp.Disable(true);
                    btnAddMaterial.Disable(true);
                    btnDelMaterial.Disable(true);
                    btnAddCustomer.Disable(true);
                }
                else
                {
                    btnSavePopUp.Enable(true);
                    btnAddMaterial.Enable(true);
                    btnDelMaterial.Enable(true);
                    btnAddCustomer.Enable(true);
                }
            }
        }
        private void GetOrderDetailGridEdit(int id)
        {
            var _dtGetOrderDetailGridEdit = _clsOrderSell.GetOrderSellDetailEdit(id);
            if (_dtGetOrderDetailGridEdit != null && _dtGetOrderDetailGridEdit.Rows.Count > 0)
            {
                StoreOrderSell_Detail.DataSource = _dtGetOrderDetailGridEdit;
                StoreOrderSell_Detail.DataBind();
            }
            else
            {
                grOrderSell_Detail.GetStore().RemoveAll();
            }
        }
        private void GetOrderDetailTemp()
        {
            var _dtGetOrderDetailTemp = _clsOrderSell.GetOrderSellDetailTemp(int.Parse(Session["Users_Id"].ToString()));
            if (_dtGetOrderDetailTemp != null && _dtGetOrderDetailTemp.Rows.Count > 0)
            {
                StoreOrderSell_Detail.DataSource = _dtGetOrderDetailTemp;
                StoreOrderSell_Detail.DataBind();
            }
            else
            {
                grOrderSell_Detail.GetStore().RemoveAll();
            }
        }
        private void GetOrderMaterialSell()
        {
            var _dtGetOrderMaterialSell = _clsOrderSell.GetOrderMaterial(string.Empty);
            if (_dtGetOrderMaterialSell != null && _dtGetOrderMaterialSell.Rows.Count > 0)
            {
                StoreOrderSell_Proposed_Materials.DataSource = _dtGetOrderMaterialSell;
                StoreOrderSell_Proposed_Materials.DataBind();
            }
            else
            {
                grOrderSell_Proposed_Materials.GetStore().RemoveAll();
            }
        }
        private void GetCustomer()
        {
            var _dtCustomer = _clsCustomer.BindGirdtb_Customer(string.Empty);
            if (_dtCustomer != null && _dtCustomer.Rows.Count > 0)
            {
                StoreCustomerSell.DataSource = _dtCustomer;
                StoreCustomerSell.DataBind();
            }
            else
            {
                grCustomerSell.GetStore().RemoveAll();
            }
        }
        private void GetCustomerEdit(int id)
        {
            var _dtCustomerEdit = _clsCustomer.GetCustomerDetail(id);
            if (_dtCustomerEdit != null && _dtCustomerEdit.Rows.Count > 0)
            {
                txtCustomerID.Text = _dtCustomerEdit.Rows[0]["Customer_ID"].ToString();
                txtCustomerAlias.Text = _dtCustomerEdit.Rows[0]["Customer_Alias"].ToString();
                txtCustomerName.Text = _dtCustomerEdit.Rows[0]["Customer_Name"].ToString();
                txtCustomerAddress.Text = _dtCustomerEdit.Rows[0]["Customer_Address"].ToString();
                txtTaxCode.Text = _dtCustomerEdit.Rows[0]["Customer_Contract_Tax_Code"].ToString();
            }
        }
        private void GetAutoID()
        {
            var _dtGetAutoID = _clsOrderSell.GetAutoID("Order_Sell_Code", "tb_Order_Sell");
            if (_dtGetAutoID != null && _dtGetAutoID.Rows.Count > 0)
            {
                try
                {
                    txtOrderSellCode.Text = "DNMH-" + DateTime.Now.ToString("yyMM") + "-000" +
                                            Convert.ToString(int.Parse(_dtGetAutoID.Rows[0]["Auto_ID"].ToString()) +
                                                             int.Parse(1.ToString()));
                }
                catch (Exception ex)
                {
                    HTML.clsFormat.Alert_ERROR("Thông Báo", ex.Message);
                }
            }
        }
        private void GetOrderSellSum()
        {
            var _dtGetSum = _clsOrderSell.GetOrderSellDetailSum(int.Parse(Session["Users_Id"].ToString()), 1);
            if (_dtGetSum != null && _dtGetSum.Rows.Count > 0)
            {
                lbQualityOrderSell.Text = _dtGetSum.Rows[0]["TotalMaterials"].ToString();
                lbPriceOrderSell.Text = String.Format("{0:0,00}", _dtGetSum.Rows[0]["TotalPrice"]).Replace(".", ",");
                lbPriCKOrderSell.Text = String.Format("{0:0,00}", _dtGetSum.Rows[0]["TotalCK"]).Replace(".", ",");
                lbPriVATOrderSell.Text = String.Format("{0:0,00}", _dtGetSum.Rows[0]["TotalVAT"]).Replace(".", ",");
                lbTotalCostOrderSell.Text = String.Format("{0:0,00}", _dtGetSum.Rows[0]["TotalPriceALL"]).Replace(".", ",");
            }
        }
        private void GetOrderSellSumEdit(int id)
        {
            var _dtGetSum = _clsOrderSell.GetOrderSellDetailSumEdit(id, 0);
            if (_dtGetSum != null && _dtGetSum.Rows.Count > 0)
            {
                lbQualityOrderSell.Text = _dtGetSum.Rows[0]["TotalMaterials"].ToString();
                lbPriceOrderSell.Text = String.Format("{0:0,00}", _dtGetSum.Rows[0]["TotalPrice"]).Replace(".", ",");
                lbPriCKOrderSell.Text = String.Format("{0:0,00}", _dtGetSum.Rows[0]["TotalCK"]).Replace(".", ",");
                lbPriVATOrderSell.Text = String.Format("{0:0,00}", _dtGetSum.Rows[0]["TotalVAT"]).Replace(".", ",");
                lbTotalCostOrderSell.Text = String.Format("{0:0,00}", _dtGetSum.Rows[0]["TotalPriceALL"]).Replace(".", ",");
                lbTotalMaterialReview.Text = String.Format("{0:0,00}", _dtGetSum.Rows[0]["TotalPriceALL"]).Replace(".", ",");
            }
        }
        private void GetOrderSellReview(int id)
        {
            var _dtGetOrderSellReview = _clsOrderSell.GetOrderSellEdit(id);
            if (_dtGetOrderSellReview != null && _dtGetOrderSellReview.Rows.Count > 0)
            {
                txtReviewOrder_Sell_Id.Text = _dtGetOrderSellReview.Rows[0]["Order_Sell_Id"].ToString();
                lbReviewOrderCode.Text = _dtGetOrderSellReview.Rows[0]["Order_Sell_Code"].ToString();
                lbReviewOrderDate.Text = String.Format("{0:dd-MM-yyyy}",
                    _dtGetOrderSellReview.Rows[0]["Order_Sell_DateBegin"]);
                lbReviewCustomer_Alias.Text = _dtGetOrderSellReview.Rows[0]["Customer_Alias"].ToString();
                lbReviewCustomer_Name.Text = _dtGetOrderSellReview.Rows[0]["Customer_Name"].ToString();
                HdCustomer_Id.Text = _dtGetOrderSellReview.Rows[0]["Customer_ID"].ToString();
                if (_dtGetOrderSellReview.Rows[0]["DateTimeReview"].ToString() == string.Empty ||
                    _dtGetOrderSellReview.Rows[0]["DateTimeReview"].ToString() == DBNull.Value.ToString())
                {
                    lbReviewDateUpdate.Text = "N/A";
                }
                else
                {
                    lbReviewDateUpdate.Text = String.Format("{0:dd-MM-yyyy}",
                        _dtGetOrderSellReview.Rows[0]["DateTimeReview"]);
                }
                if (_dtGetOrderSellReview.Rows[0]["DateTimeReview"].ToString() == string.Empty ||
                    _dtGetOrderSellReview.Rows[0]["DateTimeReview"].ToString() == DBNull.Value.ToString())
                {
                    lbReViewTime.Text = "N/A";
                }
                else
                {
                    lbReViewTime.Text = String.Format("{0:HH:mm:ss}", _dtGetOrderSellReview.Rows[0]["DateTimeReview"]);
                }
                if ((bool)_dtGetOrderSellReview.Rows[0]["IsActive"])
                {
                    lbReViewTime.IconCls = "x-icon-tick";
                    lbReviewDateUpdate.IconCls = "x-icon-tick";
                }
                if ((bool)_dtGetOrderSellReview.Rows[0]["IsActive"] == false)
                {
                    lbReViewTime.IconCls = "x-icon-cross";
                    lbReviewDateUpdate.IconCls = "x-icon-cross";
                }
                HdReviewIsActive.Text = _dtGetOrderSellReview.Rows[0]["IsActive"].ToString();
                if ((bool)_dtGetOrderSellReview.Rows[0]["IsActive"])
                {
                    btnReviewWindow.Disable(true);
                    btnUnReviewWindow.Enable(true);
                }
                else
                {
                    btnReviewWindow.Enable(true);
                    btnUnReviewWindow.Disable(true);
                }
                if ((bool) _dtGetOrderSellReview.Rows[0]["IsUsed"])
                {
                    btnReviewWindow.Disable(true);
                    btnUnReviewWindow.Disable(true);
                }
                else
                {
                    btnReviewWindow.Enable(true);
                    btnUnReviewWindow.Enable(true);
                }
            }
        }
        private void GetOrderDetailGridReview(int id)
        {
            var _dtGetOrderDetailGridReview = _clsOrderSell.GetOrderSellDetailEdit(id);
            if (_dtGetOrderDetailGridReview != null && _dtGetOrderDetailGridReview.Rows.Count > 0)
            {
                StoreOrderSellReview.DataSource = _dtGetOrderDetailGridReview;
                StoreOrderSellReview.DataBind();
            }
            else
            {
                grOrderSellReview.GetStore().RemoveAll();
            }
        }
        private void GetOrderFillterDate()
        {
            if (String.IsNullOrEmpty(txtDateBeginFillter.Text) && String.IsNullOrEmpty(txtDateEndFillter.Text))
            {
                var _dtGetOrderSell = _clsOrderSell.GetOrderSell(txtSearch.Text);
                if (_dtGetOrderSell != null && _dtGetOrderSell.Rows.Count > 0)
                {
                    StoreSell.DataSource = _dtGetOrderSell;
                    StoreSell.DataBind();
                }
                else
                {
                    grSell.GetStore().RemoveAll();
                }
            }
            else
            {
                var _dtGetOrderSell = _clsOrderSell.GetOrderSellFillterDate(txtDateBeginFillter.Text, txtDateEndFillter.Text);
                if (_dtGetOrderSell != null && _dtGetOrderSell.Rows.Count > 0)
                {
                    StoreSell.DataSource = _dtGetOrderSell;
                    StoreSell.DataBind();
                }
                else
                {
                    grSell.GetStore().RemoveAll();
                }
            }
        }
        private bool CheckInsertOrder()
        {
            bool kiemtra = false;
            var dtOrder = _clsOrderSell.GetOrderSell(string.Empty);
            if (dtOrder != null && dtOrder.Rows.Count > 0)
            {
                foreach (DataRow dr in dtOrder.Rows)
                {
                    if (txtOrderSellCode.Text == dr["Order_Sell_Code"].ToString())
                    {
                        kiemtra = true;
                    }
                }
            }
            return kiemtra;
        }
        private bool CheckInsertMaterials(int id)
        {
            bool kiemtra = false;
            var dtMaterials = _clsOrderSell.GetOrderSellDetailTemp(int.Parse(Session["Users_Id"].ToString()));
            if (dtMaterials != null && dtMaterials.Rows.Count > 0)
            {
                foreach (DataRow dr in dtMaterials.Rows)
                {
                    if (id == int.Parse(dr["Materials_Id"].ToString()))
                    {
                        kiemtra = true;
                    }
                }
            }
            return kiemtra;
        }
        private bool CheckInsertMaterialsA(int id, int Order_Sell_Id)
        {
            bool kiemtra = false;
            var dtMaterials = _clsOrderSell.GetOrderSellDetailA(int.Parse(Session["Users_Id"].ToString()), Order_Sell_Id);
            if (dtMaterials != null && dtMaterials.Rows.Count > 0)
            {
                foreach (DataRow dr in dtMaterials.Rows)
                {
                    if (id == int.Parse(dr["Materials_Id"].ToString()))
                    {
                        kiemtra = true;
                    }
                }
            }
            return kiemtra;
        }
        private void InsertOrderSell()
        {
            try
            {
                if (CheckInsertOrder())
                {
                    HTML.clsFormat.Alert_ERROR("Lỗi", "Mã hoá đơn đã tồn tại !");
                }
                else
                {
                    var dtExists = _clsOrderSell.GetOrderSellDetailExists();
                    if (dtExists != null && dtExists.Rows.Count > 0)
                    {
                        var obj = new EtOrderSell
                        {
                            Order_Sell_Code = txtOrderSellCode.Text,
                            Order_Sell_DateBegin = DateTime.Parse(txtDateBegin.Text),
                            Order_Sell_Tax_Code = txtTaxCode.Text,
                            Order_Sell_Description = txtNote.Text,
                            Order_Sell_Payment_Type = DBNull.Value.ToString(),
                            Customer_ID = int.Parse(txtCustomerID.Text),
                            IsActive = false,
                            Users_Id = int.Parse(Session["Users_Id"].ToString()),
                            Note = txtNote.Text,
                            TypeSell = "0",
                        };
                        BllOrder_Sell.InsertOrderSell(obj);
                        HTML.clsFormat.Alert_INFO("Thông Báo", "Thêm mới hoá đơn thành công !");
                        GetOrderSell();
                        ClearText();
                        GetAutoID();
                    }
                    else
                    {
                        HTML.clsFormat.Alert_ERROR("Lỗi", "Không có vật tư để cập nhật !");
                    }
                }
            }
            catch (Exception ex)
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", ex.Message);
            }
        }
        private void InsertOrderSellDetail()
        {
            try
            {
                var sm = grOrderSell_Proposed_Materials.GetSelectionModel() as CheckboxSelectionModel;
                if (sm != null)
                    foreach (var row in sm.SelectedRows)
                    {
                        try
                        {
                            if (CheckInsertMaterials(int.Parse(row.RecordID)))
                            {
                                HTML.clsFormat.Alert_ERROR("Lỗi",
                                    "Vật tư này đã tồn tại trong danh sách bán hàng !");
                            }
                            else
                            {
                                var obj = new EtOrderSellDetail
                                {
                                    Order_Sell_Id = -1,
                                    Materials_Id = int.Parse(row.RecordID),
                                    Order_Detail_Quality = 0,
                                    Order_Detail_Price = 0,
                                    Order_Detail_CK_Percent = 0,
                                    Order_Detail_CK = 0,
                                    Order_Detail_VAT_Percent = 0,
                                    Order_Detail_VAT = 0,
                                    Order_Detail_Total_Price = 0,
                                    Flag = 1,
                                    Users_Id = int.Parse(Session["Users_Id"].ToString()),
                                    Order_Detail_Quality_Remain = 0
                                };
                                BllOrder_Sell.InsertOrderSellDetail(obj);
                                if (obj.Msg == 0)
                                {
                                    HTML.clsFormat.Alert_ERROR("Thông Báo", "Số lượng vật tư không đủ để cung cấp !");
                                }
                                else
                                {
                                    HTML.clsFormat.Alert_INFO("Thông Báo", "Thêm thành công vật tư !");
                                    WindowOrderSell_Proposed_Materials.Close();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            HTML.clsFormat.Alert_ERROR("Thông Báo", ex.Message);
                        }
                    }
                GetOrderDetailTemp();
                GetOrderSellSum();
            }
            catch (Exception ex)
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", ex.Message);
            }
        }
        private void InsertOrderSellDetailEdit()
        {
            try
            {
                var sm = grOrderSell_Proposed_Materials.GetSelectionModel() as CheckboxSelectionModel;
                if (sm != null)
                    foreach (var row in sm.SelectedRows)
                    {
                        try
                        {
                            if (CheckInsertMaterialsA(int.Parse(row.RecordID), int.Parse(txtOrderSell_ID.Text)))
                            {
                                HTML.clsFormat.Alert_ERROR("Lỗi",
                                    "Vật tư này đã tồn tại trong danh sách bán hàng !");
                            }
                            else
                            {
                                var obj = new EtOrderSellDetail
                                {
                                    Order_Sell_Id = int.Parse(txtOrderSell_ID.Text),
                                    Materials_Id = int.Parse(row.RecordID),
                                    Order_Detail_Quality = 1,
                                    Order_Detail_Price = 0,
                                    Order_Detail_CK_Percent = 0,
                                    Order_Detail_CK = 0,
                                    Order_Detail_VAT_Percent = 0,
                                    Order_Detail_VAT = 0,
                                    Order_Detail_Total_Price = 0,
                                    Flag = 0,
                                    Users_Id = int.Parse(Session["Users_Id"].ToString()),
                                    Order_Detail_Quality_Remain = 0
                                };
                                BllOrder_Sell.InsertOrderSellDetail(obj);
                                if (obj.Msg == 0)
                                {
                                    HTML.clsFormat.Alert_ERROR("Thông Báo", "Số lượng vật tư không đủ để cung cấp !");
                                }
                                else
                                {
                                    HTML.clsFormat.Alert_INFO("Thông Báo", "Thêm thành công vật tư !");
                                    WindowOrderSell_Proposed_Materials.Close();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            HTML.clsFormat.Alert_ERROR("Thông Báo", ex.Message);
                        }
                    }
                GetOrderDetailGridEdit(int.Parse(txtOrderSell_ID.Text));
                GetOrderSellSumEdit(int.Parse(txtOrderSell_ID.Text));
            }
            catch (Exception ex)
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", ex.Message);
            }
        }
        private void UpdateOrder()
        {
            try
            {
                var obj = new EtOrderSell
                {
                    Order_Sell_Id = int.Parse(txtOrderSell_ID.Text),
                    Order_Sell_Tax_Code = txtTaxCode.Text,
                    Order_Sell_Description = txtNote.Text,
                    Users_Id = int.Parse(Session["Users_Id"].ToString()),
                    Note = txtNote.Text
                };
                BllOrder_Sell.UpdateOrderSell(obj);
                HTML.clsFormat.Alert_INFO("Thông Báo", "Cập nhật thành công đơn đặt hàng !");
                GetOrderSell();
                WindowsOrderSell.Close();
            }
            catch (Exception ex)
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", ex.Message);
            }
        }
        private void ReView()
        {
            try
            {
                var obj = new EtOrderSell
                {
                    Order_Sell_Id = int.Parse(txtReviewOrder_Sell_Id.Text),
                    Users_Id_Review = int.Parse(Session["Users_Id"].ToString()),
                    IsActive = true
                };
                BllOrder_Sell.Review(obj);
                //if (obj.Msg == 0)
                //    HTML.clsFormat.Alert_ERROR("Thông Báo","Phiếu đặt hàng này đã được phê duyệt !");
                //GetOrderSellReview(int.Parse(txtReviewOrder_Sell_Id.Text));
                //GetOrderDetailGridReview(int.Parse(txtReviewOrder_Sell_Id.Text));
                //GetOrderSell();
            }
            catch (Exception ex)
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", ex.Message);
            }
        }
        private void ReviewMaterial(int Order_Sell_Detail_Id)
        {
            try
            {
                var obj = new EtOrderSellDetail
                {
                    Order_Sell_Id = int.Parse(txtReviewOrder_Sell_Id.Text),
                    Order_Sell_Detail_Id = Order_Sell_Detail_Id,
                    IsActive = true
                };
                BllOrder_Sell.ReviewMaterial(obj);
                if (obj.Msg == 0)
                    HTML.clsFormat.Alert_ERROR("Thông Báo", "Số lượng không đủ để cung cấp !");
                else
                    HTML.clsFormat.Alert_INFO("Thông Báo", "Xét duyệt thành công !");
                ReView();
                GetOrderSellReview(int.Parse(txtReviewOrder_Sell_Id.Text));
                GetOrderDetailGridReview(int.Parse(txtReviewOrder_Sell_Id.Text));
                GetOrderSell();
            }
            catch (Exception ex)
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", ex.Message);
            }
        }
        private void UnReviewMaterial(int Order_Sell_Detail_Id)
        {
            try
            {
                var obj = new EtOrderSellDetail
                {
                    Order_Sell_Id = int.Parse(txtReviewOrder_Sell_Id.Text),
                    Order_Sell_Detail_Id = Order_Sell_Detail_Id,
                    IsActive = false
                };
                BllOrder_Sell.UnReviewMaterial(obj);
                HTML.clsFormat.Alert_INFO("Thông Báo", "Bỏ xét duyệt thành công !");
                GetOrderSellReview(int.Parse(txtReviewOrder_Sell_Id.Text));
                GetOrderDetailGridReview(int.Parse(txtReviewOrder_Sell_Id.Text));
                GetOrderSell();
                UnReView();

            }
            catch (Exception ex)
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", ex.Message);
            }
        }
        private void UnReView()
        {
            try
            {
                var obj = new EtOrderSell
                {
                    Order_Sell_Id = int.Parse(txtReviewOrder_Sell_Id.Text),
                    Users_Id_Review = int.Parse(Session["Users_Id"].ToString()),
                    IsActive = false
                };
                BllOrder_Sell.UnReView(obj);
                if (obj.Msg == 2)
                    HTML.clsFormat.Alert_ERROR("Thông Báo", "Phiếu đặt hàng này đang được sử dụng.Không từ chối được !");
                //GetOrderSellReview(int.Parse(txtReviewOrder_Sell_Id.Text));
                //GetOrderDetailGridReview(int.Parse(txtReviewOrder_Sell_Id.Text));
                //GetOrderSell();
            }
            catch (Exception ex)
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", ex.Message);
            }
        }
        #endregion

        #region[Clear-Text]
        private void ClearText()
        {
            lbQualityOrderSell.Text = "0";
            lbPriceOrderSell.Text = "0";
            lbPriCKOrderSell.Text = "0";
            lbPriVATOrderSell.Text = "0";
            lbTotalCostOrderSell.Text = "0";
            txtDateBegin.Text = DateTime.Now.ToString();
            txtTaxCode.Text = string.Empty;
            txtCustomerAddress.Text = string.Empty;
            txtCustomerAlias.Text = string.Empty;
            txtCustomerName.Text = string.Empty;
            txtNote.Text = string.Empty;
            SelectType.Text = string.Empty;
            txtOrderSell_ID.Text = string.Empty;
            txtCustomerID.Text = string.Empty;
            grOrderSell_Detail.GetStore().RemoveAll();
        }
        #endregion

        #region[Review]
        //Button
        protected void btnReviewWindow_Click(object sender, DirectEventArgs e)
        {
            var sm = grOrderSellReview.GetSelectionModel() as CheckboxSelectionModel;
            if (sm != null)
            {
                if (sm.SelectedRows.Count > 0)
                {
                    foreach (var row in sm.SelectedRows)
                    {
                        ReviewMaterial(int.Parse(row.RecordID));
                    }
                }
                else
                {
                    HTML.clsFormat.Alert_ERROR("Thông Báo", "Vui lòng kiểm tra số lượng trước khi xét duyệt !");
                }
            }
           
        }
        protected void btnUnReviewWindow_Click(object sender, DirectEventArgs e)
        {
            var sm = grOrderSellReview.GetSelectionModel() as CheckboxSelectionModel;
            if (sm != null)
            {
                if (sm.SelectedRows.Count > 0)
                {
                    foreach (var row in sm.SelectedRows)
                    {
                        UnReviewMaterial(int.Parse(row.RecordID));
                    }
                }
                else
                {
                    HTML.clsFormat.Alert_ERROR("Thông Báo", "Vui lòng kiểm tra số lượng trước khi xét duyệt !");
                }
            }
        }
        protected void btnReLoadReviewOrder_Click(object sender, DirectEventArgs e)
        {
            GetOrderSellReview(int.Parse(txtReviewOrder_Sell_Id.Text));
            GetOrderDetailGridReview(int.Parse(txtReviewOrder_Sell_Id.Text));
            GetOrderSellSumEdit(int.Parse(txtReviewOrder_Sell_Id.Text));
        }
        protected void btnExitReviewOrder_Click(object sender, DirectEventArgs e)
        {
            WindowOrderSellReview.Close();
        }
        //Store
        protected void StoreOrderSellReview_RefreshData(object sender, StoreReadDataEventArgs e)
        {
            GetOrderDetailGridReview(int.Parse(txtReviewOrder_Sell_Id.Text));
            GetOrderSellSumEdit(int.Parse(txtReviewOrder_Sell_Id.Text));
        }
        #endregion

        #region[Permisstion]
        private void CheckPermisstion()
        {
            if (Session["login"] != null && Session["USer_Detail_Id"].ToString() != string.Empty)
            {
                bool Is_BtnAdd;
                bool Is_BtnEdit;
                bool Is_BtnView;
                bool Is_BtnDel;
                bool Is_BtnPrint;
                bool Is_BtnCancel;
                bool Is_BtnReview;

                SecurityServices.HasPermisstion_Btn(StringContent.OrderBuySell, out Is_BtnAdd, out Is_BtnEdit, out Is_BtnDel, out Is_BtnView, out Is_BtnCancel, out Is_BtnPrint, out Is_BtnReview);
                if (Is_BtnAdd == false)
                {
                    btnAddNew.Visible = false;
                }
                if (Is_BtnEdit == false)
                {
                    btnEdit.Visible = false;
                }
                if (Is_BtnView == false)
                {
                    PanelSell.Visible = false;
                }
                if (Is_BtnDel == false)
                {
                    btnDel.Visible = false;
                }
                if (Is_BtnPrint == false)
                {
                    btnExport.Visible = false;
                }
                if (Is_BtnReview == false)
                {
                    btnReview.Visible = false;
                }
                if (Is_BtnCancel == false)
                {
                    btnUnReviewWindow.Visible = false;
                }
            }
        }
        private bool CheckPermisstionDobclick()
        {
            bool check = false;
            if (Session["login"] != null && Session["USer_Detail_Id"].ToString() != string.Empty)
            {
                bool Is_BtnAdd;
                bool Is_BtnEdit;
                bool Is_BtnView;
                bool Is_BtnDel;
                bool Is_BtnPrint;
                bool Is_BtnCancel;
                bool Is_BtnReview;

                SecurityServices.HasPermisstion_Btn(StringContent.OrderBuySell, out Is_BtnAdd, out Is_BtnEdit, out Is_BtnDel, out Is_BtnView, out Is_BtnCancel, out Is_BtnPrint, out Is_BtnReview);
                if (Is_BtnEdit == false)
                {
                    check = true;
                }
            }
            return check;
        }
        #endregion
    }
}